package com.tianzmp.ttq.admin.controller;


import com.tianzmp.ttq.admin.common.BaseResult;
import com.tianzmp.ttq.admin.common.Result;
import com.tianzmp.ttq.admin.controller.reqDto.UserInfoSaveDTO;
import com.tianzmp.ttq.admin.controller.resDto.UserInfoDto;
import com.tianzmp.ttq.admin.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @author zhumengping
 */
@RestController
@RequestMapping("/admin/login")
@Api(value = "user login")
@Log4j2
public class LoginController {

    @Autowired
    private ILoginService loginService;


    @ApiOperation(value = "user register",notes = "",httpMethod = "POST")
    @PostMapping(value = "/register")
    public BaseResult<Boolean> register(@Valid @RequestBody UserInfoSaveDTO dto){
        return Result.ok(loginService.registerUser(dto));
    }


    @ApiOperation(value = "user login",notes = "",httpMethod = "POST")
    @PostMapping(value = "/s")
    public BaseResult<UserInfoDto> login(
            @RequestParam(value = "account") String account,
            @RequestParam(value = "password") String password){
        return Result.ok(loginService.findByUserName(account, password));
    }

    @ApiOperation(value = "rest password",notes = "重置密码",httpMethod = "GET")
    @GetMapping(value = "/rest/{userId}")
    public BaseResult<Boolean> rest(@PathVariable("userId") Long userId){
        return Result.ok(loginService.restPassword(userId));
    }


}
